import asyncio
import logging
from datetime import datetime
from aiowebsocket.converses import AioWebSocket


async def startup(uri):
    print('{time}-Client connet'.format(time=datetime.now().strftime('%Y-%m-%d %H:%M:%S')))

    async with AioWebSocket(uri) as aws:
        converse = aws.manipulator
        message = b'AioWebSocket - Async WebSocket Client'
        while True:
            await converse.send(message)
            print('{time}-Client send: {message}'
                  .format(time=datetime.now().strftime('%Y-%m-%d %H:%M:%S'), message=message))
            mes = await converse.receive()
            print('{time}-Client receive: {rec}'
                  .format(time=datetime.now().strftime('%Y-%m-%d %H:%M:%S'), rec=mes))
            await asyncio.sleep(3)

if __name__ == '__main__':
    # remote = 'ws://echo.websocket.org'
    uri = "ws://localhost:8000/feed2"
    try:
        asyncio.get_event_loop().run_until_complete(startup(uri))
    except KeyboardInterrupt as exc:
        logging.info('Quit.')
